package edu.albany.assassin;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends Activity {
	private Button myButton =null;
	private Button myButton1 =null;
	private Button registerb =null;
	private EditText widget40;
	private EditText widget41;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        widget40 = (EditText) findViewById(R.id.widget40);
        widget41 = (EditText) findViewById(R.id.widget41);
        myButton = (Button)findViewById(R.id.myButton);
        myButton.setText("Connect");
        myButton1 = (Button)findViewById(R.id.myButton1);
        myButton1.setText("Login");
        myButton1.setOnClickListener(new LoginListener());
        registerb = (Button)findViewById(R.id.registerb);
        registerb.setText("Register");
        registerb.setOnClickListener(new MyBListener());
    }
    
    class MyBListener implements OnClickListener{

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent=new Intent();
			intent.setClass(MainActivity.this, CreateAccountActivity.class);
			MainActivity.this.startActivity(intent);
		}
   }
    class LoginListener implements OnClickListener{

		public void onClick(View v) {
			// TODO Auto-generated method stub
			String username = widget40.getText().toString();
			String password = widget41.getText().toString();
			if (username.matches("")) {
				Context context = getApplicationContext();
				CharSequence text = "Please enter email!";
				int duration = Toast.LENGTH_SHORT;
				Toast toast = Toast.makeText(context, text, duration);
				toast.show();
			}
			if ((!(username.equals("jazzhu")))&&(!((username.matches(""))))) {
				Context context = getApplicationContext();
				CharSequence text = "Wrong email!";
				int duration = Toast.LENGTH_SHORT;
				Toast toast = Toast.makeText(context, text, duration);
				toast.show();
			}
			if (password.matches("")&&(!(username.matches("")))) {
				Context context = getApplicationContext();
				CharSequence text = "Please enter password!";
				int duration = Toast.LENGTH_SHORT;
				Toast toast = Toast.makeText(context, text, duration);
				toast.show();
			}
			if ((!(password.equals("jazzhu")))&&(!((password.matches(""))))) {
				Context context = getApplicationContext();
				CharSequence text = "Wrong Password!";
				int duration = Toast.LENGTH_SHORT;
				Toast toast = Toast.makeText(context, text, duration);
				toast.show();
			}
			if ((username.equals("jazzhu"))&&(password.equals("jazzhu"))) {
					// TODO Auto-generated method stub
					Intent intent=new Intent();
					intent.setClass(MainActivity.this, PersonalPage.class);
					MainActivity.this.startActivity(intent);
				
				
			}
		}
   }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}